<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <meta charset="utf-8">
    <title>小说审核</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/static/layui/css/layui.css" media="all" />
</head>
<body class="childrenBody">

<table id="SignInforData" lay-filter="newsList"></table>

<!--操作-->
<script type="text/html" id="newsListBar">
    <a class="layui-btn layui-btn-normal layui-btn-sm" lay-event="ok">同意</a>
    <a class="layui-btn layui-btn-danger layui-btn-sm" lay-event="no">拒绝</a>
    <%-- <a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="del">删除</a>
     <a class="layui-btn layui-btn-xs layui-btn-primary" lay-event="look">预览</a>--%>
</script>
<script type="text/javascript" src="${pageContext.request.contextPath}/static/layui/layui.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/static/js/dateFormat.js"></script>
<script>

    layui.use(['laydate','layer','jquery','table'], function(){
        var layer = layui.layer;
        var $ = layui.jquery;
        var table = layui.table;

        table.render({
            elem: '#SignInforData',
            url : '${pageContext.request.contextPath}/admin/getLbProp',
            cellMinWidth : 95,
            toolbar:"default",
            page : true,
            limit : 15,
            limits : [15,20,30,40,50],
            id : "newsList",
            cols : [[
                /* {type: "checkbox", fixed:"left", width:50},*/
                {field: 'novelName', title: '小说名称', align:'center'},
                {field: 'lbName', title: '轮播图',  align:'center',templet: function (data) {
                        return "<img height='100px'  src='${pageContext.request.contextPath}/static/images/lb/"+data.lbName+"'>"
                    }},
                {title: '状态', fixed:"right", align:"center",templet:function (data) {
                        if(data.isCurrent == 1){return "<a class=\"layui-btn layui-btn-normal layui-btn-sm\" >当前轮播</a>"}
                        if(data.isCurrent == 0){return ""}
                    }},
                {title: '状态', fixed:"right", align:"center",templet:function (data) {
                        if(data.isCurrent == 1){return "<a class=\"layui-btn layui-btn-warm layui-btn-sm\" lay-event=\"no\" >移除</a>"}
                        if(data.isCurrent == 0){return "<a class=\"layui-btn layui-btn-primary layui-btn-sm\" lay-event=\"ok\">设为轮播</a>"}
                    }}
            ]]
        });

        function myTableReload(obj) {
            //执行重载
            table.reload('newsList', {
                page: {
                    curr: 1 //重新从第 1 页开始
                }
                , where: obj

            });
        }

        table.on('tool(newsList)', function(obj){ //注：tool 是工具条事件名，test 是 table 原始容器的属性 lay-filter="对应的值"
            var data = obj.data //获得当前行数据
                ,layEvent = obj.event; //获得 lay-event 对应的值
            if(layEvent === 'ok'){
                layer.confirm('确定设为轮播', function(d){
                    $.ajax({
                        type:"get",
                        url: "${pageContext.request.contextPath}/admin/addLb/"+data.id,
                        success:function (data) {
                            if(data.success){
                                layer.msg(data.message,{icon: 1}),function (index) {
                                    layer.close(index);
                                }
                                // obj.del(); //删除对应行（tr）的DOM结构
                                myTableReload();
                            }else {
                                layer.msg(data.message,{icon: 5})
                            }
                        },
                    });
                });
            }else if(layEvent === 'no'){
                layer.confirm('确定移除轮播', function(d){
                    $.ajax({
                        type:"POST",
                        url: "${pageContext.request.contextPath}/admin/removeLb/"+data.id,
                        success:function (data) {
                            if(data.success){
                                layer.msg(data.message,{icon: 1}),function (index) {

                                    layer.close(index);
                                }
                                // obj.del(); //删除对应行（tr）的DOM结构
                                myTableReload();
                            }else {
                                layer.msg(data.message,{icon: 5})
                            }
                        },
                    });
                });
            }
        });
    });

</script>
</body>
</html>

